package work.xkong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import work.xkong.common.ResponseRest;
import work.xkong.entity.Admin;
import work.xkong.entity.Admin;
import work.xkong.mapper.AdminMapper;
import work.xkong.service.IAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 * @since 2022-11-21
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public ResponseRest login(String username, String password) {
        LambdaQueryWrapper<Admin> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Admin::getAdminUsername, username);

        Admin admin = adminMapper.selectOne(lqw);

        if (admin != null && admin.getAdminPassword().equals(password)){
            return ResponseRest.creatSuccess("恭喜你登录成功",admin);
        }

        return ResponseRest.creatFail("账号或密码错误，请重新登录");
    }
}
